calculateNPeriodReturns <- function(TS, Filter, n, includeSymName=FALSE, verbose=FALSE, method="close_t0") {
  if (verbose==TRUE) {
    symname = strsplit(colnames(TS)[1] ,".", fixed=TRUE)
    cat("calculate ", symname[[1]][1], "\n")
  }
  if (method=="close_t0") { # open position at close of pattern
    returns <- do.call(cbind, lapply(1:n, function(i) {
      lag(ROC(Cl(TS), i, type="discrete"), -i)[Filter]
    }))    
  } else if (method=="close_t1") {
    Filter <- Lag(Filter)
    returns <- do.call(cbind, lapply(1:n, function(i) {
      lag(ROC(Cl(TS), i, type="discrete"), -i)[Filter]
    }))
  }

  if (verbose==TRUE) {cat("returns calculated.\n")}  
  if (length(returns) == 0) {
    if (verbose==TRUE) {cat("filter contained no trues.\n")}    
    return(data.frame()) # if there are no trues in filter, return empty data.frame
  }
  colnames(returns) <- 1:n
  returnsdf <- as.data.frame(returns)
  if (includeSymName==TRUE) {
    symname = strsplit(colnames(TS)[1] ,".", fixed=TRUE)
    row.names(returnsdf) <- paste(row.names(returnsdf), symname[[1]][1])
  }
  if (verbose==TRUE) {cat("exiting calculateNPeriodReturns\n")}
  return(returnsdf)
}